package com.first.group.authserver.controller;

import java.util.Arrays;
import java.util.Map;

import com.first.group.authserver.config.OSSFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.first.group.authserver.entity.UserEntity;
import com.first.group.authserver.service.UserService;
import com.first.group.common.utils.PageUtils;
import com.first.group.common.utils.R;
import org.springframework.web.multipart.MultipartFile;


/**
 * 这是前台用户表
 *
 * @author zy
 * @email 2067065884@qq.com
 * @date 2021-10-14 19:09:10
 */
@RestController
@RequestMapping("authserver/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);

        return R.ok().put("page", page);
    }

    @PostMapping("/upload")
    public String upload(MultipartFile file) {
        return OSSFileUtil.uploadDuanFile(file);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{userId}")
    public R info(@PathVariable("userId") Long userId){
		UserEntity user = userService.getById(userId);

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody UserEntity user){


        return userService.saveUser(user);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserEntity user){


        return userService.updateUser(user);
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] userIds){
		userService.removeByIds(Arrays.asList(userIds));

        return R.ok();
    }

}
